﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Globalization;
using ForumsBrowser.Common;

namespace ForumsBrowser
{
    /// <summary>
    /// Interaction logic for CultureSelector.xaml
    /// </summary>
    public partial class CultureSelector : UserControl
    {
        public CultureInfo SelectedCulture = Configuration.Culture;

        public CultureSelector()
        {
            InitializeComponent();
            listBox1.SelectedItem = Configuration.Culture;
            
        }

        protected override void OnRender(DrawingContext drawingContext)
        {
            listBox1.ScrollIntoView(Configuration.Culture);
            base.OnRender(drawingContext);
        }

        private void listBox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0)
                SelectedCulture = e.AddedItems[0] as CultureInfo;
        }
    }

    public class CultureList : List<CultureInfo>
    {
        public CultureList() : base(CultureInfo.GetCultures(CultureTypes.SpecificCultures).OrderBy(k => k.DisplayName)) { }
    }
}
